<template>
  <div>
    <div class="container">
      <div class="login-form">
        <h1 class="h1" style="color: #000; fontsize: 28px">
          微信小程序健身管理系统注册
        </h1>
        <el-form class="rgs-form">
          <el-form-item label="账号" class="input">
            <el-input
              v-model="ruleForm.username"
              autocomplete="off"
              placeholder="账号"
            />
          </el-form-item>
          <el-form-item label="密码" class="input">
            <el-input
              type="password"
              v-model="ruleForm.password"
              autocomplete="off"
              placeholder="请输入密码"
              show-password
            />
          </el-form-item>
          <el-form-item label="重复密码" class="input">
            <el-input
              type="passwo   rd"
              v-model="ruleForm.repetitionPassword"
              autocomplete="off"
              placeholder="请再次输入密码"
              show-password
            />
          </el-form-item>
          <el-form-item
            label="健身教练名称"
            class="input"
            v-if="tableName == 'shangjia'"
          >
            <el-input
              v-model="ruleForm.shangjiaName"
              autocomplete="off"
              placeholder="健身教练名称"
            />
          </el-form-item>
          <el-form-item
            label="联系方式"
            class="input"
            v-if="tableName == 'shangjia'"
          >
            <el-input
              v-model="ruleForm.shangjiaPhone"
              autocomplete="off"
              placeholder="联系方式"
            />
          </el-form-item>
          <el-form-item
            label="邮箱"
            class="input"
            v-if="tableName == 'shangjia'"
          >
            <el-input
              v-model="ruleForm.shangjiaEmail"
              autocomplete="off"
              placeholder="邮箱"
            />
          </el-form-item>
          <el-form-item
            label="用户姓名"
            class="input"
            v-if="tableName == 'yonghu'"
          >
            <el-input
              v-model="ruleForm.yonghuName"
              autocomplete="off"
              placeholder="用户姓名"
            />
          </el-form-item>
          <el-form-item
            label="联系方式"
            class="input"
            v-if="tableName == 'yonghu'"
          >
            <el-input
              v-model="ruleForm.yonghuPhone"
              autocomplete="off"
              placeholder="联系方式"
            />
          </el-form-item>
          <el-form-item
            label="身份证号"
            class="input"
            v-if="tableName == 'yonghu'"
          >
            <el-input
              v-model="ruleForm.yonghuIdNumber"
              autocomplete="off"
              placeholder="身份证号"
            />
          </el-form-item>
          <el-form-item
            label="电子邮箱"
            class="input"
            v-if="tableName == 'yonghu'"
          >
            <el-input
              v-model="ruleForm.yonghuEmail"
              autocomplete="off"
              placeholder="电子邮箱"
            />
          </el-form-item>
          <div
            style="
              display: flex;
              flex-wrap: wrap;
              width: 100%;
              justify-content: center;
            "
          >
            <el-button class="btn" type="primary" @click="login()"
              >注册</el-button
            >
            <el-button class="btn close" type="primary" @click="close()"
              >取消</el-button
            >
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {},
      tableName: "",
      rules: {},
      sexTypesOptions: [],
      shangjiaPhotoFlag: false, //用于刷新文件上传
      yonghuPhotoFlag: false, //用于刷新文件上传
    };
  },
  mounted() {
    let table = this.$storage.get("loginTable");
    this.tableName = table;

    //级联表的下拉框查询
  },
  methods: {
    // 获取uuid
    getUUID() {
      return new Date().getTime();
    },
    shangjiaPhotoUploadChange(fileUrls) {
      this.ruleForm.shangjiaPhoto = fileUrls;
      if (this.shangjiaPhotoFlag) {
        this.shangjiaPhotoFlag = false;
      } else {
        this.shangjiaPhotoFlag = true;
      }
    },
    yonghuPhotoUploadChange(fileUrls) {
      this.ruleForm.yonghuPhoto = fileUrls;
      if (this.yonghuPhotoFlag) {
        this.yonghuPhotoFlag = false;
      } else {
        this.yonghuPhotoFlag = true;
      }
    },
    close() {
      this.$router.push({ path: "/login" });
    },
    // 注册
    login() {
      if (!this.ruleForm.username) {
        this.$message.error("账号不能为空");
        return;
      }
      if (!this.ruleForm.password) {
        this.$message.error("密码不能为空");
        return;
      }
      if (!this.ruleForm.repetitionPassword) {
        this.$message.error("重复密码不能为空");
        return;
      }
      if (this.ruleForm.repetitionPassword != this.ruleForm.password) {
        this.$message.error("密码和重复密码不一致");
        return;
      }
      if (!this.ruleForm.shangjiaName && "shangjia" == this.tableName) {
        this.$message.error("健身教练名称不能为空");
        return;
      }
      if (
        "shangjia" == this.tableName &&
        this.ruleForm.shangjiaPhone &&
        !this.$validate.isMobile(this.ruleForm.shangjiaPhone)
      ) {
        this.$message.error("手机应输入手机格式");
        return;
      }
      if (
        "shangjia" == this.tableName &&
        this.ruleForm.shangjiaEmail &&
        !this.$validate.isEmail(this.ruleForm.shangjiaEmail)
      ) {
        this.$message.error("邮箱应输入邮件格式");
        return;
      }
      if (!this.ruleForm.yonghuName && "yonghu" == this.tableName) {
        this.$message.error("用户姓名不能为空");
        return;
      }
      if (
        "yonghu" == this.tableName &&
        this.ruleForm.yonghuPhone &&
        !this.$validate.isMobile(this.ruleForm.yonghuPhone)
      ) {
        this.$message.error("手机应输入手机格式");
        return;
      }
      if (!this.ruleForm.yonghuIdNumber && "yonghu" == this.tableName) {
        this.$message.error("身份证号不能为空");
        return;
      }
      if (
        "yonghu" == this.tableName &&
        this.ruleForm.yonghuEmail &&
        !this.$validate.isEmail(this.ruleForm.yonghuEmail)
      ) {
        this.$message.error("邮箱应输入邮件格式");
        return;
      }
      this.$http({
        url: `${this.tableName}/register`,
        method: "post",
        data: this.ruleForm,
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.$message({
            message: "注册成功,请登录后在个人中心页面补充个人数据",
            type: "success",
            duration: 1500,
            onClose: () => {
              this.$router.replace({ path: "/login" });
            },
          });
        } else {
          this.$message.error(data.msg);
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.el-radio__input.is-checked .el-radio__inner {
  border-color: #00c292;
  background: #00c292;
}

.el-radio__input.is-checked .el-radio__inner {
  border-color: #00c292;
  background: #00c292;
}

.el-radio__input.is-checked .el-radio__inner {
  border-color: #00c292;
  background: #00c292;
}

.el-radio__input.is-checked + .el-radio__label {
  color: #00c292;
}

.el-radio__input.is-checked + .el-radio__label {
  color: #00c292;
}

.el-radio__input.is-checked + .el-radio__label {
  color: #00c292;
}

.h1 {
  margin-top: 10px;
}

body {
  padding: 0;
  margin: 0;
}

.nk-navigation {
  margin-top: 15px;

  a {
    display: inline-block;
    color: #fff;
    background: rgba(255, 255, 255, 0.2);
    width: 100px;
    height: 50px;
    border-radius: 30px;
    text-align: center;
    display: flex;
    align-items: center;
    margin: 0 auto;
    justify-content: center;
    padding: 0 20px;
  }

  .icon {
    margin-left: 10px;
    width: 30px;
    height: 30px;
  }
}

.register-container {
  margin-top: 10px;

  a {
    display: inline-block;
    color: #fff;
    max-width: 500px;
    height: 50px;
    border-radius: 30px;
    text-align: center;
    display: flex;
    align-items: center;
    margin: 0 auto;
    justify-content: center;
    padding: 0 20px;

    div {
      margin-left: 10px;
    }
  }
}

.container {
  height: 100vh;
  background-position: center center;
  background-size: cover;
  background-repeat: no-repeat;
  background-image: url(https://ts1.tc.mm.bing.net/th/id/R-C.18f7d7918e5aefb0598c4a0cb2eccbf1?rik=ryGD0pbQLJ221w&riu=http%3a%2f%2ffitimg.yunimg.cn%2fproduction%2fpost%2f201909%2f156929192361825.jpg&ehk=YgVxF4%2b66AOe9hi6Y%2blYmGXdN4tEpvV613ZnobcO%2fvA%3d&risl=1&pid=ImgRaw&r=0);

  .login-form {
    right: 50%;
    top: 50%;
    transform: translate3d(50%, -50%, 0);
    border-radius: 10px;
    background-color: rgba(255, 255, 255, 0.5);
    font-size: 14px;
    font-weight: 500;
    box-sizing: border-box;

    width: 450px;
    height: auto;
    padding: 0;
    margin: 0;
    border-radius: 50px;
    border-width: 3px;
    border-style: solid;
    border-color: var(--publicMainColor);
    background-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0px 15px rgba(255, 255, 255, 1);

    .h1 {
      width: 400px;
      height: 80px;
      line-height: 80px;
      color: #000;
      font-size: 18px;
      padding: 0;
      margin: 10px 0px 20px 10px;
      border-radius: 0;
      border-width: 0;
      border-style: solid;
      border-color: rgba(237, 237, 237, 1);
      background-color: rgba(255, 69, 0, 0);
      box-shadow: 0 0 6px rgba(255, 0, 0, 0);
      text-align: center;
    }

    .rgs-form {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      .el-form-item {
        width: 100%;
        display: flex;

        & /deep/ .el-form-item__content {
          flex: 1;
          display: flex;
        }
      }

      .input {
        width: 360px;
        height: 40px;
        padding: 0;
        margin: 0px 0px 10px 50px;
        border-radius: 0;
        border-width: 0;
        border-style: solid;
        border-color: rgba(255, 0, 0, 0);
        background-color: rgba(144, 238, 144, 0);
        box-shadow: 0 0 6px rgba(255, 0, 0, 0);

        & /deep/ .el-form-item__label {
          width: 100px;
          line-height: 40px;
          color: rgba(0, 0, 0, 1);
          font-size: 16px;
          padding: 0px 0px 0px 0px;
          margin: 0px 0px 0px -15px;
          border-radius: 0;
          border-width: 0;
          border-style: solid;
          border-color: rgba(255, 0, 0, 0);
          background-color: rgba(144, 238, 144, 0);
          box-shadow: 0 0 6px rgba(255, 0, 0, 0);
        }

        & /deep/ .el-input__inner {
          width: 200px;
          height: 40px;
          line-height: 40px;
          color: var(--publicSubColor);
          font-size: 14px;
          padding: 0px 0px 0px 10px;
          margin: 0px 0px 0px 10px;
          border-radius: 20px;
          border-width: 3px;
          border-style: solid;
          border-color: var(--publicSubColor);
          background-color: rgba(255, 255, 255, 1);
          box-shadow: 0 0 6px rgba(255, 0, 0, 0);
          text-align: left;
        }
      }

      .send-code {
        & /deep/ .el-input__inner {
          width: 120px;
          height: 40px;
          line-height: 40px;
          color: #fff;
          font-size: 14px;
          padding: 0px 12px 0px 0px;
          margin: 0px 0px 0px 10px;
          border-radius: 20px 0px 0px 20px;
          border-width: 3px;
          border-style: solid;
          border-color: var(--publicMainColor);
          background-color: rgba(255, 255, 255, 0.8);
          box-shadow: 0 0 6px rgba(255, 0, 0, 0);
          text-align: left;
        }

        .register-code {
          margin: 0px 0px 0px 0px;
          padding: 5px;
          width: 80px;
          height: 40px;
          line-height: 40px;
          color: #fff;
          font-size: 14px;
          border-width: 0;
          border-style: solid;
          border-color: rgba(255, 0, 0, 0);
          border-radius: 0 20px 20px 0;
          background-color: rgba(96, 98, 102, 1);
          box-shadow: 0 0 6px rgba(255, 0, 0, 0);
        }
      }

      .btn {
        margin: 10px 60px 40px 0px;
        padding: 0;
        width: 88px;
        height: 32px;
        line-height: 32px;
        color: #fff;
        font-size: 14px;
        border-width: 0;
        border-style: solid;
        border-color: #409eff;
        border-radius: 20px;
        background-color: var(--publicSubColor);
        box-shadow: 0 0 0px 4px rgba(255, 255, 255, 1);
      }

      .close {
        margin: 10px 20px 40px 0px;
        padding: 0;
        width: 88px;
        height: 32px;
        line-height: 32px;
        color: rgba(255, 255, 255, 1);
        font-size: 14px;
        border-width: 0;
        border-style: solid;
        border-color: #409eff;
        border-radius: 20px;
        background-color: var(--publicMainColor);
        box-shadow: 0 0 0px 5px rgba(255, 255, 255, 1);
      }
    }
  }
}
</style>


